package com.yfqy.app.modules.pay.resource;

import com.yfqy.app.domain.vo.ResultVO;
import com.yfqy.app.modules.order.dto.PrepaymentDTO;
import com.yfqy.app.modules.pay.service.PayService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/client/pay")
public class PayController {

    @Autowired
    private PayService paymentService;


    /**
     * 生成小程序支付参数
     */
    @PostMapping("/jsapi/prepay")
    public ResultVO<Map<String, Object>> generateJsApiPrePay(@Valid @RequestBody PrepaymentDTO prepayment) {
        Map<String, Object> result = paymentService.generateJsApiPrePay(prepayment);
        return ResultVO.data(result);
    }

    /**
     * 主动查询微信支付结果
     */
    @GetMapping("/jsapi/orderquery/{orderNo}")
    public ResultVO<String> orderQuery(@PathVariable String orderNo) {
        String result = paymentService.orderquery(orderNo);
        return ResultVO.data(result);
    }
}
